package com.ruoyi.performance.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.performance.domain.PerfLevelScore;
import com.ruoyi.performance.service.PerfLevelScoreService;
import com.ruoyi.performance.utils.MyUtils;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author YL
 * @date 2020-07-22
 * @description 绩效等级分数区间控制层
 */
@RestController
@RequestMapping("levelscore")
public class PerfLevelScoreController extends MyUtils {
	
	@Resource
	private PerfLevelScoreService perfLevelScoreService;

	/**
     * 根据id查找绩效等级分数区间
     * @param id 绩效等级分数区间id
     * @return 绩效等级分数区间
     */
	@GetMapping("get")
	public R list(int id){
		Map<String, Object> m = new HashMap<>(16);
		m.put("rows", perfLevelScoreService.selectPerfLevelScoreById(id));
		return R.ok(m);
	}
	/**
	 * 查询绩效等级分数区间列表
	 */
	@GetMapping("list")
	public R list(PerfLevelScore perfLevelScore) {
		startPage();
        return result(perfLevelScoreService.selectPerfLevelScoreList(perfLevelScore));
	}
	
	
	/**
	 * 新增保存绩效等级分数区间
	 */
	@PostMapping("save")
	public R addSave(@RequestBody PerfLevelScore perfLevelScore) {
		return toAjax(perfLevelScoreService.insertPerfLevelScore(perfLevelScore));
	}

	/**
	 * 修改保存绩效等级分数区间
	 */
	@PostMapping("update")
	public R editSave(@RequestBody PerfLevelScore perfLevelScore) {
		int row=perfLevelScoreService.updatePerfLevelScore(perfLevelScore);
		if (row==-1){
			return R.error(505,"绩效模板发布后禁止修改等级！");
		}
		return toAjax(row);
	}

	@PostMapping("remove")
	public Map<String,String> remove(String ids) {
		return jacResultMsg(perfLevelScoreService.deletePerfLevelScoreById(ids));
	}
	
}
